﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WorkStation.Frameworks.EasyBus.Pipeline.Filters;
using WorkStation.Frameworks.EasyBus.Pipeline.Handles;

namespace WorkStation.Frameworks.EasyBus.Pipeline.Modules
{
    /// <summary>
    /// 处理模块接口（根据输入类型分组）
    /// </summary>
    public interface IModule
    {
        /// <summary>
        /// 处理的输入类型
        /// </summary>
        string ProcessType { get; set; }

        /// <summary>
        /// 处理器
        /// </summary>
        Dictionary<string, IHandle> Handles { get; set; }

        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="context">执行上下文</param>
        /// <returns></returns>
        IEnumerable<HandleResult> Process(ActionContext context);

        /// <summary>
        /// 订阅
        /// </summary>
        /// <param name="handle">处理器</param>
        /// <returns></returns>
        IModule Subscribe(IHandle handle);

        /// <summary>
        /// 顺序
        /// </summary>
        int Order { get; set; }

        /// <summary>
        /// 订阅
        /// </summary>
        /// <param name="func">处理内容委托</param>
        /// <param name="handleName">处理器名称，不输入则以对象的HashCode替代</param>
        /// <param name="filter">过滤器</param>
        /// <returns></returns>
        IModule Subscribe(Func<ActionContext, IHandle, HandleResult> func, string handleName = null, IFilter filter = null, int order = -1);

        /// <summary>
        /// 订阅异步处理
        /// </summary>
        /// <param name="func">处理内容委托</param>
        /// <param name="handleName">处理器名称，不输入则以对象的HashCode替代</param>
        /// <param name="filter">过滤器</param>
        /// <returns></returns>
        IModule AsyncSubscribe(Func<ActionContext, IHandle, HandleResult> func, string handleName = null, IFilter filter = null);

        /// <summary>
        /// 退订
        /// </summary>
        /// <param name="handleName">处理器名称</param>
        /// <returns></returns>
        IModule UnSubscribe(string handleName);
    }
}
